//package bank;
package FM2_15577.front_end;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;

public class BankSystemGUI {
    private JFrame frame;
    private JPanel panel;
    private JButton userRegisterButton;
    private JButton userLoginButton;
    private JButton adminLoginButton;
    private JButton adminRegisterButton;
    private JButton createReportButton, importFileButton, queryAndExportButton;
    // private String attrText = "";
    // private char[] pwd = {};
    private long mnt = 0;
    private static BankSystem bs = new BankSystem();

    /**
     * Method Description: Default constructor, initializes the system interface
     */
    public BankSystemGUI() {
    	frame = new JFrame("Bank System");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 300);
    	mainGUI();
    }
    
    /**
     * Method description: Build the main screen with user registration, user login and administrator login
     */
    public void mainGUI() {
    	frame.getContentPane().removeAll();
        frame.repaint();
        panel = new JPanel();
        panel.setLayout(new GridLayout(3, 1));

        userRegisterButton = new JButton("User Register");
        userRegisterButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                showUserRegisterPage();
            }
        });
        
        userLoginButton = new JButton("User Login");
        userLoginButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                showUserLoginPage();
            }
        });

        adminLoginButton = new JButton("Admin Login");
        adminLoginButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                showAdminLoginPage();
            }
        });

        panel.add(userRegisterButton);
        panel.add(userLoginButton);
        panel.add(adminLoginButton);

        frame.add(panel);
        frame.setVisible(true);
    }

    /**
     * Method description: Build user registration interface
     */
    private void showUserRegisterPage() {
    	frame.getContentPane().removeAll();
        frame.repaint();
        
        JPanel userRegisterPanel = new JPanel();
        userRegisterPanel.setLayout(new GridLayout(7, 2));

        JLabel nameLabel = new JLabel("Name:");
        JTextField nameField = new JTextField();

        JLabel passwordLabel = new JLabel("Password:");
        JTextField passwordField = new JPasswordField();

        JLabel idLabel = new JLabel("ID:");
        JTextField idField = new JTextField();

        JLabel phoneLabel = new JLabel("Phone:");
        JTextField phoneField = new JTextField();

        JLabel birthdayLabel = new JLabel("Birthday:");
        JTextField birthdayField = new JTextField("YYYY-MM-DD");

        JLabel gen = new JLabel("Gender:");
        String[] gend = {"Female", "Male"};
        JComboBox<String> jcb1 = new JComboBox<String>(gend);
        

        JButton regisButton = new JButton("Register");
        regisButton.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) {
                try {
                    bs.registerAccount(
                        bs.checkAndConvertName(nameField.getText()), 
                        bs.checkAndConvertCipher(passwordField.getText()), 
                        bs.checkAndConvertID(idField.getText()), 
                        bs.checkAndConvertPhone(phoneField.getText()), 
                        bs.checkAndConvertSex(jcb1.getSelectedItem().toString().substring(0, 1)), 
                        bs.checkAndConvertDob(birthdayField.getText())
                    );
                    JOptionPane.showMessageDialog(null, "Success", "Success", JOptionPane.INFORMATION_MESSAGE);
                    showUserFunctionalityPage();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                }
        	}
        });
        
        JButton returnButton = new JButton("Return");
        returnButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                bs.logout();
            	mainGUI();
            }
        });
        // 
        userRegisterPanel.add(nameLabel);
        userRegisterPanel.add(nameField);
        userRegisterPanel.add(passwordLabel);
        userRegisterPanel.add(passwordField);
        userRegisterPanel.add(idLabel);
        userRegisterPanel.add(idField);
        userRegisterPanel.add(phoneLabel);
        userRegisterPanel.add(phoneField);
        userRegisterPanel.add(birthdayLabel);
        userRegisterPanel.add(birthdayField);
        userRegisterPanel.add(gen);
        userRegisterPanel.add(jcb1);
        // userRegisterPanel.add(amountLabel);
        // userRegisterPanel.add(amountField);
       
        userRegisterPanel.add(returnButton); 
        userRegisterPanel.add(regisButton);

        frame.add(userRegisterPanel);
        frame.setVisible(true);
    }
    
    /**
     * Method description: Build user login interface
     */
    private void showUserLoginPage() {
        frame.getContentPane().removeAll();
        frame.repaint();

        JPanel userLoginPanel = new JPanel();
        userLoginPanel.setLayout(new GridLayout(3, 2));

        JLabel aidLabel = new JLabel("Account ID:");
        JTextField aidField = new JTextField();

        JLabel passwordLabel = new JLabel("Password:");
        JTextField passwordField = new JPasswordField();

        JButton loginButton = new JButton("Login");
        loginButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    bs.loginAccount(
                        bs.checkAndConvertAid(aidField.getText()), 
                        bs.checkAndConvertCipher(passwordField.getText())
                    );
                    JOptionPane.showMessageDialog(null, "Success", "Success", JOptionPane.INFORMATION_MESSAGE);
                    showUserFunctionalityPage();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        JButton returnButton = new JButton("Return");
        returnButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                bs.logout();
            	mainGUI();
            }
        });

        userLoginPanel.add(aidLabel);
        userLoginPanel.add(aidField);
        userLoginPanel.add(passwordLabel);
        userLoginPanel.add(passwordField);

        userLoginPanel.add(returnButton);
        userLoginPanel.add(loginButton);
        

        frame.add(userLoginPanel);
        frame.setVisible(true);
    }
    
    /**
     * Method description: User balance inquiry interface
     */
    private void showAmountPage(long userMnt) {
    	frame.getContentPane().removeAll();
        frame.repaint();

        JPanel mntPanel = new JPanel();
        mntPanel.setLayout(new GridLayout(2, 1));

        String balance;
        try {
            balance = bs.getBalance().toString();
        } catch (Exception ex) {
            balance = ex.getMessage();
            JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        
        JLabel mntLabel = new JLabel("Balance: "+balance);
        // JTextField mntField = new JTextField(userMnt+"");
        mntPanel.add(mntLabel);
        // mntPanel.add(mntField);
        
        // JButton updateButton = new JButton("Update");
        // updateButton.addActionListener(new ActionListener() {
        // 	public void actionPerformed(ActionEvent e) {
        //     	showMntUpdatePage();
        // 	}
        // });
        
        // mntPanel.add(updateButton);
        
        JButton returnButton = new JButton("Return");
        returnButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	showUserFunctionalityPage();
            }
        });
        
        mntPanel.add(returnButton);
        
        frame.add(mntPanel);
        frame.setVisible(true);

    }
    
    /**
     * Method description: User balance update interface
     */
    private void showMntUpdatePage() {
    	frame.getContentPane().removeAll();
        frame.repaint();

        JPanel newMntPanel = new JPanel();
        newMntPanel.setLayout(new GridLayout(3, 2));
        
        JLabel opt = new JLabel("Operation:");
        String[] optr = {"Deposit", "Withdraw"};
        JComboBox<String> jcb2 = new JComboBox<String>(optr);
        newMntPanel.add(opt);
        newMntPanel.add(jcb2);
        
        JLabel newMntLabel = new JLabel("Amount:");
        JTextField newMntField = new JTextField(15);
        newMntPanel.add(newMntLabel);
        newMntPanel.add(newMntField);
        
        JButton submitButton = new JButton("Submit");
        submitButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    if (jcb2.getSelectedItem().equals("Deposit")) {
                        bs.deposit(bs.checkAndConvertAmount(newMntField.getText()));
                    }
                    else {
                        bs.withdraw(bs.checkAndConvertAmount(newMntField.getText()));
                    }
                    JOptionPane.showMessageDialog(null, "Success", "Success", JOptionPane.INFORMATION_MESSAGE);
                    showUserFunctionalityPage();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        JButton returnButton = new JButton("Return");
        returnButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	showUserFunctionalityPage();
            }
        });
        
        newMntPanel.add(submitButton);
        newMntPanel.add(returnButton);
        
        frame.add(newMntPanel);
        frame.setVisible(true);
    }
    
    /**
     * Method description: User information update interface
     */
    private void showUpdatePage() {
    	frame.getContentPane().removeAll();
        frame.repaint();

        JPanel newUpdPanel = new JPanel();
        newUpdPanel.setLayout(new GridLayout(5, 2));
        
        JLabel newNameLabel = new JLabel("New name:");
        JTextField newNameField = new JTextField(15);
        newUpdPanel.add(newNameLabel);
        newUpdPanel.add(newNameField);
        
        JLabel newPasswordLabel = new JLabel("New password:");
        JTextField newPasswordField = new JPasswordField();
        newUpdPanel.add(newPasswordLabel);
        newUpdPanel.add(newPasswordField);
        
        JLabel newPhoneLabel = new JLabel("New phone number:");
        JTextField newPhoneField = new JTextField();
        newUpdPanel.add(newPhoneLabel);
        newUpdPanel.add(newPhoneField);
        
        JLabel genderLabel = new JLabel("New gender:");
        String[] gend = {"Female", "Male"};
        JComboBox<String> jcb1 = new JComboBox<String>(gend);
        newUpdPanel.add(genderLabel);
        newUpdPanel.add(jcb1);
        
        JButton submitButton = new JButton("Submit");
        submitButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
        		/* check and process */
                try {
                    bs.updateInfo(
                        bs.checkAndConvertName(newNameField.getText()), 
                        bs.checkAndConvertCipher(newPasswordField.getText()), 
                        bs.checkAndConvertPhone(newPhoneField.getText()), 
                        bs.checkAndConvertSex(jcb1.getSelectedItem().toString().substring(0, 1))
                    );
                    JOptionPane.showMessageDialog(null, "Success", "Success", JOptionPane.INFORMATION_MESSAGE);
                    showUserFunctionalityPage();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        JButton returnButton = new JButton("Return");
        returnButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	showUserFunctionalityPage();
            }
        });
        
        newUpdPanel.add(submitButton);
        newUpdPanel.add(returnButton);
        
        frame.add(newUpdPanel);
        frame.setVisible(true);
    }

    /**
     * Method description: Balance transfer interface
     */
    private void showTransferPage() {
    	frame.getContentPane().removeAll();
        frame.repaint();

        JPanel transPanel = new JPanel();
        transPanel.setLayout(new GridLayout(3, 2));
        
        JLabel transIDLabel = new JLabel("Target Account ID:");
        JTextField transIDField = new JTextField(15);
        transPanel.add(transIDLabel);
        transPanel.add(transIDField);
        
        JLabel transAmountLabel = new JLabel("Transfer Amount:");
        JTextField transAmountField = new JTextField();
        transPanel.add(transAmountLabel);
        transPanel.add(transAmountField);
        
        
        JButton submitButton = new JButton("Submit");
        submitButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
        		/* check and process */
                try {
                    bs.transfer(
                        bs.checkAndConvertAid(transIDField.getText()), 
                        bs.checkAndConvertAmount(transAmountField.getText())
                    );
                    JOptionPane.showMessageDialog(null, "Success", "Success", JOptionPane.INFORMATION_MESSAGE);
                    showUserFunctionalityPage();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        JButton returnButton = new JButton("Return");
        returnButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	showUserFunctionalityPage();
            }
        });
        
        transPanel.add(submitButton);
        transPanel.add(returnButton);
        
        frame.add(transPanel);
        frame.setVisible(true);
    }
    
    /**
     * Method description: User function interface
     */
    private void showUserFunctionalityPage() {
        frame.getContentPane().removeAll();
        frame.repaint();

        JPanel userFunctionalityPanel = new JPanel();
        userFunctionalityPanel.setLayout(new GridLayout(7, 1));

        JLabel curAccountInfoLabel = new JLabel(String.format("Current Account: %d", bs.getAccount()));

        JButton checkBalanceButton = new JButton("Check Balance");
        checkBalanceButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	showAmountPage(mnt);
            }
        });

        JButton updateAccountButton = new JButton("Update Account Information");
        updateAccountButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	showUpdatePage();
            }
        });

        JButton depositButton = new JButton("Deposit/Withdraw");
        depositButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	showMntUpdatePage();
            }
        });

        JButton delButton = new JButton("Delete account");
        delButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	int i = JOptionPane.showConfirmDialog(null,"Your account and user information will be deleted. Confirm you want to continue?", "Delete account", JOptionPane.YES_NO_OPTION);
            	if(i==0)
            	{
            		/* delete account */
                    try {
                        bs.removeAccount(bs.getAccount());
                        JOptionPane.showMessageDialog(null, "Success", "Success", JOptionPane.INFORMATION_MESSAGE);
                        bs.logout();
                        mainGUI();
                    } catch (Exception ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                    }
            	}
            }
        });

        JButton transferButton = new JButton("Transfer");
        transferButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	showTransferPage();
            }
        });
        
        JButton returnButton = new JButton("Return");
        returnButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                bs.logout();
            	mainGUI();
            }
        });

        userFunctionalityPanel.add(curAccountInfoLabel);
        userFunctionalityPanel.add(checkBalanceButton);
        userFunctionalityPanel.add(updateAccountButton);
        userFunctionalityPanel.add(depositButton);
        userFunctionalityPanel.add(delButton);
        userFunctionalityPanel.add(transferButton);
        userFunctionalityPanel.add(returnButton);

        frame.add(userFunctionalityPanel);
        frame.setVisible(true);
    }

    /**
     * Method description: Build administrator login screen
     */
    private void showAdminLoginPage() {
        frame.getContentPane().removeAll();
        frame.repaint();

        JPanel adminLoginPanel = new JPanel();
        adminLoginPanel.setLayout(new GridLayout(3, 2));

        JLabel nameLabel = new JLabel("Name:");
        JTextField nameField = new JTextField();

        JLabel passwordLabel = new JLabel("Password:");
        JTextField passwordField = new JPasswordField();

        JButton loginButton = new JButton("Login");
        loginButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    bs.loginAdminAccount(
                        bs.checkAndConvertAdminName(nameField.getText()), 
                        bs.checkAndConvertCipher(passwordField.getText())
                    );
                    JOptionPane.showMessageDialog(null, "Success", "Success", JOptionPane.INFORMATION_MESSAGE);
                    showAdminFunctionalityPage();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        JButton returnButton = new JButton("Return");
        returnButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                bs.logout();
            	mainGUI();
            }
        });

        adminLoginPanel.add(nameLabel);
        adminLoginPanel.add(nameField);
        adminLoginPanel.add(passwordLabel);
        adminLoginPanel.add(passwordField);
        adminLoginPanel.add(returnButton);
        adminLoginPanel.add(loginButton);
        

        frame.add(adminLoginPanel);
        frame.setVisible(true);
    }

    /**
     * Method description: Build administrator register page
     */
    private void showAdminRegisterPage() {
        frame.getContentPane().removeAll();
        frame.repaint();

        JPanel adminRegisterPanel = new JPanel();
        adminRegisterPanel.setLayout(new GridLayout(3, 2));

        JLabel nameLabel = new JLabel("Name:");
        JTextField nameField = new JTextField();

        adminRegisterPanel.add(nameLabel);
        adminRegisterPanel.add(nameField);
        
        JLabel passwordLabel = new JLabel("Password:");
        JTextField passwordField = new JPasswordField();
        adminRegisterPanel.add(passwordLabel);
        adminRegisterPanel.add(passwordField);

        JButton registerButton = new JButton("Submit");
        registerButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    bs.registerAdminAccount(
                        bs.checkAndConvertAdminName(nameField.getText()), 
                        bs.checkAndConvertCipher(passwordField.getText())
                    );
                    JOptionPane.showMessageDialog(null, "Success", "Success", JOptionPane.INFORMATION_MESSAGE);
                    showAdminFunctionalityPage();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        JButton returnButton = new JButton("Return");
        returnButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                showAdminFunctionalityPage();
            }
        });

        adminRegisterPanel.add(returnButton);
        adminRegisterPanel.add(registerButton);
        

        frame.add(adminRegisterPanel);
        frame.setVisible(true);
    }
    
    /**
     * Method description: Import data files by selecting files
     */
    private void showChooseFilePage() {
    	frame.getContentPane().removeAll();
        frame.repaint();

        JPanel filePanel = new JPanel();
        FlowLayout layout = new FlowLayout();
        layout.setAlignment(FlowLayout.CENTER);
        filePanel.setLayout(layout);
        
        JLabel fileLabel = new JLabel("Please choose the file:");
        JTextField fileField = new JTextField(15);
        JButton fileButton = new JButton("Browse");
        fileButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	JFileChooser chooser = new JFileChooser();
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                chooser.showDialog(new JLabel(), "Choose");
                File file = chooser.getSelectedFile();
                try {
                fileField.setText(file.getAbsoluteFile().toString());
                } catch (NullPointerException ex) {
                	/* input file is null */
                	fileField.setText("");
                }
            }
        });
        
        filePanel.add(fileLabel);
        filePanel.add(fileField);
        filePanel.add(fileButton);
        
        JLabel spaceLabel = new JLabel("");
        JButton submitButton = new JButton("Submit");
        submitButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	// attrText = fileField.getText();
        		/* check and process */
                try {
                    String res = bs.registerAccountFromXls(fileField.getText());
                    JOptionPane.showMessageDialog(null, res, "Success", JOptionPane.INFORMATION_MESSAGE);
                    showAdminFunctionalityPage();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        JButton returnButton = new JButton("Return");
        returnButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	showAdminFunctionalityPage();
            }
        });
        
        filePanel.add(submitButton);
        filePanel.add(spaceLabel);
        filePanel.add(returnButton);
        
        frame.add(filePanel);
        frame.setVisible(true);
    }
    
    /**
     * Method description: Query and export interface
     */
    private void showQueryExportPage() {
    	frame.getContentPane().removeAll();
        frame.repaint();

        JPanel filePanel = new JPanel();
        FlowLayout layout = new FlowLayout();
        layout.setAlignment(FlowLayout.CENTER);
        filePanel.setLayout(layout);
        
        JLabel fileLabel = new JLabel("Please choose the directory:");
        JTextField fileField = new JTextField(15);
        JButton fileButton = new JButton("Browse");
        fileButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	JFileChooser chooser = new JFileChooser();
                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                chooser.showDialog(new JLabel(), "Choose");
                File file = chooser.getSelectedFile();
                try {
                	fileField.setText(file.getAbsoluteFile().toString());
                } catch (NullPointerException ex) {
                	/* input file is null */
                	fileField.setText("");
                }
            }
        });
        
        filePanel.add(fileLabel);
        filePanel.add(fileField);
        filePanel.add(fileButton);
        
        JLabel spaceLabel = new JLabel("");
        JButton submitButton = new JButton("Submit");
        submitButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    bs.exportAccountInfo(fileField.getText());
                    JOptionPane.showMessageDialog(null, "Success", "Success", JOptionPane.INFORMATION_MESSAGE);
                    showAdminFunctionalityPage();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        JButton returnButton = new JButton("Return");
        returnButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	showAdminFunctionalityPage();
            }
        });
        
        filePanel.add(submitButton);
        filePanel.add(spaceLabel);
        filePanel.add(returnButton);
        
        frame.add(filePanel);
        frame.setVisible(true);
    }
    
    /**
     * Method description: Export report interface
     */
    private void showExportReportPage() {
    	frame.getContentPane().removeAll();
        frame.repaint();

        JPanel filePanel = new JPanel();
        FlowLayout layout = new FlowLayout();
        layout.setAlignment(FlowLayout.CENTER);
        filePanel.setLayout(layout);
        
        JLabel fileLabel = new JLabel("Please choose the directory:");
        JTextField fileField = new JTextField(15);
        JButton fileButton = new JButton("Browse");
        fileButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	JFileChooser chooser = new JFileChooser();
                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                chooser.showDialog(new JLabel(), "Choose");
                File file = chooser.getSelectedFile();
                try {
                	fileField.setText(file.getAbsoluteFile().toString());
                } catch (NullPointerException ex) {
                	/* input file is null */
                	fileField.setText("");
                }
            }
        });
        
        filePanel.add(fileLabel);
        filePanel.add(fileField);
        filePanel.add(fileButton);
        
        JLabel spaceLabel = new JLabel("");
        JButton submitButton = new JButton("Submit");
        submitButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    bs.exportReport(fileField.getText());
                    JOptionPane.showMessageDialog(null, "Success", "Success", JOptionPane.INFORMATION_MESSAGE);
                    showAdminFunctionalityPage();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        JButton returnButton = new JButton("Return");
        returnButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	showAdminFunctionalityPage();
            }
        });
        
        filePanel.add(submitButton);
        filePanel.add(spaceLabel);
        filePanel.add(returnButton);
        
        frame.add(filePanel);
        frame.setVisible(true);
    }
    
    /**
     * Method description: Build administrator function interface
     */
    private void showAdminFunctionalityPage() {
        frame.getContentPane().removeAll();
        frame.repaint();

        JPanel adminFunctionalityPanel = new JPanel();
        adminFunctionalityPanel.setLayout(new GridLayout(6, 1));

        JLabel curAccountInfoLabel = new JLabel(String.format("Current Account: %s", bs.getAdmin()));
        adminFunctionalityPanel.add(curAccountInfoLabel);

        adminRegisterButton = new JButton("Admin register");
        adminRegisterButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	showAdminRegisterPage();
            }
        });

        adminFunctionalityPanel.add(adminRegisterButton);
        
        createReportButton = new JButton("Create report");
        createReportButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                showExportReportPage();
            }
        });

        adminFunctionalityPanel.add(createReportButton);
        
        importFileButton = new JButton("Create users from xls file");
        importFileButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	showChooseFilePage();
            }
        });

        adminFunctionalityPanel.add(importFileButton);
        
        queryAndExportButton = new JButton("Query and export");
        queryAndExportButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	showQueryExportPage();
            }
        });

        adminFunctionalityPanel.add(queryAndExportButton);
        
        JButton returnButton = new JButton("Return");
        returnButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                bs.logout();
            	mainGUI();
            }
        });
        
        adminFunctionalityPanel.add(returnButton);

        frame.add(adminFunctionalityPanel);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new BankSystemGUI();
            }
        });
    }
}